# import random
# class A(object):
#     def __init__(self,name,age):
#         self.name = name
#         self.__age = age
#
#     def __learn(self,km):
#         print(f"我能学习{km}")
#
#     @classmethod
#     def __A_classmethod(cls):
#         print("A的classmethod")
#
# class B(A):
#     def __init__(self,name,age,addr):
#         super(B, self).__init__(name ,age)
#         self.addr=addr
#     # def show_age(self):
#     #     print("我的年龄是" , self.__age)
#     def learn(self, km):
#         super(B, self).__learn(km)
#         print("花费的时间" , random.randint(1,4))
#
#     @classmethod
#     def A_classmethod(cls):
#
#         super(B, cls).A_classmethod()
#
# s1=B('张三',22,'成都')
# s1.learn('yuwen')


# class A(object):
#     def eat(self):
#         print('能吃一桶')
#
# class B(A):
#     def walk(self):
#         print('话多')
#
# class C(A):
#     def run(self):
#         print('跑一公里')
#
# class D(B,C):
#     def jump(self):
#         print('跳起来')
#
# s = D()
# s.eat()



# a=10
# try:
#     print('运行到这了')
#     print(a)
#     # print(b)
#     print(1/0)
# except(NameError,ZeroDivisionError):
#     if NameError:
#         print('名字错误')
#     else:
#         print('分母不能为0')
#
# except Exception as err:
#
#     print('发生了其他错误')
#     print('具体错误',err)
#
# finally:
#
#     print('运行完')


# 1.判断数字
# try:
#     a = input('请输入：')
#     float(a)
# except Exception as e:
#     print('不是数字')

# 2.读取文件类，读取错误，提示原因
# import csv
# class Read_user(object):
#     def __init__(self,filename):
#         self.filename = filename
#
#     def read(self):
#         try:
#             with open(file=self.filename,mode='r',encoding='utf8') as f:
#                 file = csv.DictReader(f,delimiter=',',fieldnames=['id','name','age'])
#                 # f = list(file)
#                 f = [dict(i) for i in file]
#                 for i in f:
#                     i['age'] = int(i['age'])
#                 print(f)
#         except Exception as e:
#             print(e)
#             # print(f'请确认文件名{self.filename}是否正确')

# if __name__ == '__main__':
#     user = Read_user('test.txt')
#     user.read()



# 3.优化db，出现错误提示一下
# import pymysql
# class DB(object):
#     def __init__(self,curtype='dict',**kwargs):
#         self.__db_info = {"host":'localhost',"port":3316,"user":'root',"password":'654321',"charset":'utf8',"database":'woniubook'}
#         self.__db_info.update(kwargs)
#         self.__curtype = curtype
#         self.__connect()
#
#     def __connect(self):
#         try:
#             self.__cnn = pymysql.connect(**self.__db_info)
#             if self.__curtype == "dict":
#                 self.__cur = self.__cnn.cursor(pymysql.cursors.DictCursor)
#             elif self.__curtype == "tuple":
#                 self.__cur = self.__cnn.cursor()
#             else:
#                 # 报错？如果报错？
#                 raise Exception("传入的cursortype参数错误！")
#         except Exception as e:
#             print(e)
#
#     def update(self, sql, sql_args=None):
#         """
#         修改数据
#         :param sql: sql语句
#         :param sql_args: sql语句的参数
#         :return: 返回受印象的行数 （整数）
#         """
#         try:
#             self.__cnn.begin()  # 开启事务
#             rows = self.__cur.execute(sql, sql_args)  # 执行sql，获取数据
#             if rows < 1:
#                 print(f"Warnning: 受印象的行数是0，可能你的sql语句有错误。( {sql} )")
#             self.__cnn.commit()  # 提交事务
#
#         except:
#             print('有错误')
#         else:
#             return rows
#
#     def query(self, sql, sql_args=None):
#         """
#         :param sql:  查询语句
#         :param sql_args:  查询语句的参数
#         :return: 返回 （行数，列名，数据）
#         """
#         # 返回结果 【可以是列表（不要忘记高速我列名是什么），或  字典】
#         try:
#             rows = self.__cur.execute(sql, sql_args)  # 执行sql，获取数据
#             data = self.__cur.fetchall()
#             fields = [i[0] for i in self.__cur.description]  # 列名
#         except:
#             print('请检查您的sql语句')
#         else:
#             return data
#
#     def __del__(self):
#         """关闭游标，关闭连接"""
#         try:
#             self.__cur.close()
#             self.__cnn.close()
#         except:
#             pass
#
# if __name__ == '__main__':
#     woniusales=DB(curtype="dict")
#     user=woniusales.query("select * from user ")
#     print("用户有--->",user)






